package com.mapull.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

/**
 * 获取一天开始与结束时间点
 * @author mapull
 */
public class MapullStartDay {

    public static void main(String[] args) {
//        getStart();
//        getStartOf();
//        getStartEnd();
//        getStartAndEnd();
//        getStartAndEndWith();
        getStartAndEndZone();
    }

    private static void getStart(){
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime start = date.toLocalDate().atStartOfDay();
        System.out.println(date);
        System.out.println(start);
    }

    private static void getStartOf(){
        LocalDate date = LocalDate.now();
        LocalDateTime start = LocalDateTime.of(date, LocalTime.MIN);
        LocalDateTime mid = LocalDateTime.of(date, LocalTime.NOON);
        LocalDateTime end = LocalDateTime.of(date, LocalTime.MAX);
        System.out.println(date);
        System.out.println(start);
        System.out.println(mid);
        System.out.println(end);
    }

    private static void getStartEnd(){
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime start = date.toLocalDate().atTime(LocalTime.MIN);
        LocalDateTime mid = date.toLocalDate().atTime(LocalTime.NOON);
        LocalDateTime end = date.toLocalDate().atTime(LocalTime.MAX);
        System.out.println(date);
        System.out.println(start);
        System.out.println(mid);
        System.out.println(end);
    }

    private static void getStartAndEnd(){
        LocalDate date = LocalDate.now();
        LocalDateTime start = LocalTime.MIN.atDate(date);
        LocalDateTime mid = LocalTime.NOON.atDate(date);
        LocalDateTime end = LocalTime.MAX.atDate(date);
        System.out.println(date);
        System.out.println(start);
        System.out.println(mid);
        System.out.println(end);
    }

    private static void getStartAndEndWith(){
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime start = date.with(ChronoField.NANO_OF_DAY, LocalTime.MIN.toNanoOfDay());
        LocalDateTime end = date.with(ChronoField.NANO_OF_DAY, LocalTime.MAX.toNanoOfDay());
        System.out.println(date);
        System.out.println(start);
        System.out.println(end);
    }

    private static void getStartAndEndZone(){
        ZonedDateTime date = ZonedDateTime.now();
        ZonedDateTime start = date.with(ChronoField.NANO_OF_DAY, 0);
        ZonedDateTime end = date.with(ChronoField.NANO_OF_DAY, 86400L * 1000_000_000L - 1);
        System.out.println(date);
        System.out.println(start);
        System.out.println(end);
    }
}
